import { defineConfig } from "vite"
import vue from '@vitejs/plugin-vue'
import { createHtmlPlugin } from 'vite-plugin-html'

const htmlParams = {
  minify: true,
  pages: [
    {
      filename: 'index',     // filename 默认是template文件名，就是index.html
      entry: '/src/main.ts',
      template: 'index.html',
    }
  ]
}

export default defineConfig({
  base: './',               // 方便打包后预览
  publicDir: 'public',      // 默认 public
  plugins: [vue(), createHtmlPlugin(htmlParams)],
  build: {
    cssCodeSplit: true,
    emptyOutDir: true,
    sourcemap: false,
    assetsDir: 'assets', // 默认 assets
    outDir: 'dist',      // 默认 dist
    rollupOptions: {
      input: {},       // input 不用管，插件内会处理
      output: {
        compact: true,
        entryFileNames: "static/js/[name]-[hash].js",
        chunkFileNames: "static/js/[name]-[hash].js",
        assetFileNames: "static/[ext]/[name].[ext]",
      }
    }
  }
})
